#ifndef AUDIODECODEIMPL_H
#define AUDIODECODEIMPL_H
#include "Receive_handler.h"
#include "Task_Base/CriticalSection.h"
#include "libavinclude.h"
#include <queue>
using namespace std;
struct AVStream;
class AudioAbstract;
class AudioDecodeImpl:  public Receive_handler
{
public:
    AudioDecodeImpl(AudioAbstract *event);
    ~AudioDecodeImpl();
public:
    bool Init(AVStream*stream);
    bool UnInit();
    virtual bool receive_handler(const char *data,int size);
public:
    unsigned int read_data(char *data, unsigned int maxlen);
    double  get_audio_clock();
    int     get_queue_size();
private:
    bool pop_audio_packet(AVPacket &);
    void push_audio_packet(AVPacket &);
    int  audio_decode_frame();
    void clear_list();
private:
    AVStream            *m_pAStream;

    CCriticalSection    oListSection;
    std::queue<AVPacket>m_AVPacketList;

    AVFrame				*m_pFrame;
    struct SwrContext	*au_convert_ctx;

    uint8_t				*out_buffer;

	AVPacket			pkt_temp;
	AVPacket			pkt_cur;

    unsigned int		audio_buf_size;
    unsigned int		audio_buf_index;

    double				audio_clock;

    AudioAbstract   *m_oAudioAbstract;
};

#endif // AUDIODECODEIMPL_H
